package com.sl.biz.modular.workflow.controller;


import com.sl.biz.modular.workflow.dao.domain.entity.WorkflowInstanceDO;
import com.sl.biz.modular.workflow.domain.request.WorkflowInstanceNextByNodeCodeRequest;
import com.sl.biz.modular.workflow.domain.request.WorkflowInstanceNextRequest;
import com.sl.biz.modular.workflow.domain.request.WorkflowInstanceStartRequest;
import com.sl.biz.modular.workflow.service.WorkflowInstanceBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/work_flow/instance")
@RequiredArgsConstructor
public class WorkflowInstanceController {

    private final WorkflowInstanceBizService workflowInstanceBizService;

    @PostMapping("/list")
    public List<WorkflowInstanceDO> list(@RequestBody @Validated WorkflowInstanceDO workflowInstanceDO) {
        return workflowInstanceBizService.list(workflowInstanceDO);
    }

    @PostMapping("/get_by_id")
    public WorkflowInstanceDO getById(@RequestBody @Validated WorkflowInstanceDO workflowInstanceDO) {
        return workflowInstanceBizService.getById(workflowInstanceDO);
    }



    @PostMapping("/start")
    public String start(@RequestBody @Validated WorkflowInstanceStartRequest startRequest) {
        return workflowInstanceBizService.start(startRequest);
    }


    @PostMapping("/next")
    public String next(@RequestBody @Validated WorkflowInstanceNextRequest startRequest) {
        return workflowInstanceBizService.next(startRequest);
    }

    @PostMapping("/next_by_node_code")
    public String nextByNodeCode(@RequestBody @Validated WorkflowInstanceNextByNodeCodeRequest startRequest) {
        return workflowInstanceBizService.nextByNodeCode(startRequest);
    }

}
